package com.gxr.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import util.StrConvert;

import com.pro.bean.Unit;
import com.pro.bean.Users;
import com.dao.ObjectDao;



public class RegServlet extends HttpServlet {

	/**
	 * ��д�û���Ϣ�ύ��servlet������ݿ� ������ ��ȡ�û���Ϣ��<%=basePath%>servlet/SerchUserServlet
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		request.setCharacterEncoding("UTF-8");
		doPost(request,response);
	}

	/**
	 * 
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		request.setCharacterEncoding("UTF-8");
		String username=request.getParameter("username");
		System.out.println("adduser:"+username);
		
		String password=request.getParameter("password1");
		String email=request.getParameter("email");
		String company=request.getParameter("company");
		
		//System.out.println(company);
		//out.println(username);
		//out.println(company);
		HttpSession session=request.getSession();
		session.setAttribute("username", username);
		session.setAttribute("password", password);
		session.setAttribute("email", email);
		session.setAttribute("company", company);

		Users user=new Users();
		user.setUsername(username);
		user.setPassword(password);
		user.setEmail(email);
		user.setUnitid(Integer.parseInt(request.getParameter("company")));
		//user.setUnitid(Integer.getInteger(company));
		//System.out.println(Integer.getInteger(company));

/*		UserDao userdao=new UserDao();
		userdao.add(user);*/
		ObjectDao objectDao = new ObjectDao();
		try {
			objectDao.add(user, objectDao.NOTINSERTID);
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		

		RequestDispatcher dispatcher=request.getRequestDispatcher("SearchUserServlet");
		dispatcher.forward(request, response);
		//response.sendRedirect("SearchServlet");
	}

}
